#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAX_SIZE 5

typedef struct Queue{
    int items[MAX_SIZE];
    int front;
    int rear;
    int size;
}Queue;

Queue* init_queue(){
    Queue *q = (Queue*)malloc(sizeof(Queue));
    if(q == NULL){
        exit(1);
    }
    q->front = 0;
    q->rear = 0;
    q->size = 0;
    return q;
}

bool isEmpty(Queue* q){
    return q->size == 0;
}

bool isFull(Queue* q){
    return q->size == MAX_SIZE;
}

int getSize(Queue* q){
    return q->size;
}

void enQueue(Queue* q,int data){
    if(isFull(q)){
        printf("queue is full!\n");
        return;
    }
        q->items[q->rear] = data;
        q->rear = (q->rear + 1)% MAX_SIZE;
        q->size++;
}

int dequeue(Queue* q){
    if(isEmpty(q)){
        printf("empty queue!\n");
        return false;
    }

    int item = q->items[q->front];
    q->front = (q->front + 1)% MAX_SIZE;
    q->size--;
    return item;
}


int front(Queue* q){
    if(isEmpty(q)){
        printf("queue is empty\n");
        return -1;
    }
    return q->items[q->front];
}


int main(){
    Queue *q = init_queue();
    enQueue(q,10);
    enQueue(q,30);
    enQueue(q,50);
    printf("%d\n",front(q));
    dequeue(q);
    printf("%d \n",front(q));
    dequeue(q);
    printf("%d \n",front(q));

}